//
//  UserActivityDetailViewController.m
//  FNer
//
//  Created by 王展 on 15/10/8.
//  Copyright (c) 2015年 wangzhan. All rights reserved.
//

#import "UserActivityDetailViewController.h"
#import "UIActivityIndicatorView+AFNetworking.h"

@interface UserActivityDetailViewController ()

@property(nonatomic,retain)UIWebView *webView;
@property(nonatomic,retain)UILabel *titleLabel;
@property(nonatomic,retain)UIActivityIndicatorView *activity;

@end

@implementation UserActivityDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 40)];
    self.titleLabel.text = @"详情";
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.font = [UIFont systemFontOfSize:18 * XWIDTH];
    self.titleLabel.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = self.titleLabel;
    
    NSString *string = [[NSUserDefaults standardUserDefaults] objectForKey:@"nighting"];
    if ([string isEqualToString:@"yes"]) {
#warning 改的颜色
        self.titleLabel.textColor = [UIColor blackColor];
    }
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeColoring:) name:@"changeColoring" object:nil];
    
    //创建WebView
    self.webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, HIGHT - 64)];
    self.webView.backgroundColor = [UIColor blackColor];
    self.webView.delegate = self;
    [self.webView setScalesPageToFit:YES];
    NSString *wangZhi = self.ahtWorld.worldURL;
    NSURL *url = [NSURL URLWithString:wangZhi];
    NSURLRequest *requset = [NSURLRequest requestWithURL:url];
    [self.webView loadRequest:requset];
    [self.view addSubview:self.webView];
    
    //左方返回按钮
    UIImage *leftImage = [UIImage imageNamed:@"导航栏_button_back_用于白和灰.png"];
    leftImage = [leftImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:leftImage style:UIBarButtonItemStylePlain target:self action:@selector(leftButtonAction)];

    
    //创建小菊花
    _activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
    _activity.center =self.view.center;
    [self.view addSubview:_activity];
}

//点击左方返回按钮触发事件
-(void)leftButtonAction
{
    [self.navigationController popViewControllerAnimated:NO];
}


-(void)changeColoring:(NSNotification *)notification
{
#warning 改的颜色
    self.titleLabel.textColor = [UIColor blackColor];
    
    NSString *string = [notification object];
    if ([string isEqualToString:@"no"]) {
        
#warning 原有颜色
        self.titleLabel.textColor = [UIColor whiteColor];
    }
    //保存当前状态值
    [[NSUserDefaults standardUserDefaults] setObject:string forKey:@"nighting"];
}



-(void)webViewDidStartLoad:(UIWebView *)webView
{
    [_activity startAnimating];
    
}
-(void)webViewDidFinishLoad:(UIWebView *)webView
{
    [_activity stopAnimating];
    
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    [_activity stopAnimating];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
